aboutsummaryrefslogtreecommitdiff
path: root/src/pages/blog/[...slug].astro
blob: 3cfdf31fa4d27a093680c6ceb422f99346e25097 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
import { type CollectionEntry, getCollection } from "astro:content";
import Comments from "../../components/Comments.astro";
import Layout from "../../layouts/BaseLayout.astro";
import blogPostSchema from "../../utils/schemas/blogPostSchema";
import dayjs from "dayjs";

type Props = CollectionEntry<"blog">;

export async function getStaticPaths() {
	const posts = await getCollection("blog", ({ data }) => {
		return data.draft !== true;
	});

	return posts.map((post) => ({
		params: { slug: post.slug },
		props: post,
	}));
}

const post = Astro.props;

const { Content, remarkPluginFrontmatter } = await post.render();

const title = post.data.title;
const description = post.data.description;
const author = post.data.author;
const lang = post.data.lang;

const formattedData = dayjs(post.data.pubDate.toString()).format("MMMM DD, YYYY");
const data = post.data.pubDate.toISOString();

const schema = blogPostSchema({
	siteUrl: new URL("/", Astro.site).toString(),
	title,
	description,
	slug: post.slug,
	datePublished: data,
	author,
	lang,
});
---

<style lang="scss">
	@use "../../scss/variables" as *;

	p {
		opacity: 0.5;
	}
</style>

<Layout title={title} description={description} lang={lang} schema={schema}>
	<article>
		<header>
			<h1>{title}</h1>

			<p>
				<small>
					Posted
					<time datetime={data} lang="en">{formattedData}</time>
					by&nbsp;{author}
					<span>&nbsp;•&nbsp;</span>
					<span>{remarkPluginFrontmatter.minutesRead}</span>
				</small>
			</p>
		</header>

		<section>
			<Content />
		</section>

		<section>
			<Comments />
		</section>
	</article>
</Layout>